//
//  ByCellRedNote.m
//  mijifen_ios
//
//  Created by mc on 2017/10/24.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByCellRedNote.h"

@interface ByCellRedNote()<UITextViewDelegate>
@end

@implementation ByCellRedNote
{
    UIView      *_bgView;
    UILabel     *_titleLabel;
    UITextView  *_textView;
}

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByCellRedNote";
    ByCellRedNote *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.backgroundColor = [UIColor clearColor];
        [self createViews];
    }
    return self;
}

- (void)createViews{
    _bgView = [[UIView alloc] init];
    [self.contentView addSubview:_bgView];
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(15);
        make.top.equalTo(self.mas_top);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 30, 50));
    }];
    _bgView.backgroundColor = [UIColor whiteColor];
    
    _titleLabel = [[UILabel alloc] init];
    [_bgView addSubview:_titleLabel];
    CGFloat width = [@"使用条件：" getSizeOfString:16].width;
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_bgView.mas_top).offset(10);
        make.left.equalTo(_bgView.mas_left).offset(10);
        make.size.mas_equalTo(CGSizeMake(width, 30));
    }];
    _titleLabel.font = FONT(16);
    _titleLabel.text = @"备注：";
    
    _textView = [[UITextView alloc] init];
    [_bgView addSubview:_textView];
    [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_titleLabel.mas_right).offset(10);
        make.top.equalTo(_titleLabel.mas_top);
        make.right.equalTo(_bgView.mas_right).offset(-10);
        make.bottom.equalTo(_bgView.mas_bottom).offset(-10);
    }];
    _textView.font = FONT(16);
    _textView.delegate = self;
}

- (void)textViewDidEndEditing:(UITextView *)textView{
    if (self.redNoteBlock) {
        self.redNoteBlock(textView.text);
    }
}


@end
